<?php include "include/function_library.php"; ?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php include "html/header.html"; ?>

</head>
<body class="tcuk home">

	<div id="wp">
	
		<?php  include "html/menu.html"; ?>
		
		<!-- CONTENT STARTS-->
		<div id="ct">
			<?php if(get("deleted") == "1") echo "<div class='alert success'>Tour Deleted Successfully!</div>";	?>
			
			<div id="query_area">
				<!--  Query Area Html Part -->
				<fieldset>
				<legend>&nbsp;&nbsp;Filter results:</legend>
				<form action="<?php echo curPageURL(); ?>" method="post">
					<input type="text" name="q_name" id="q_name" placeholder="Tour Name" />
					
					<input type="text" name="q_location" id="q_location" placeholder="Tour Location" />
					
					<input type="date" name="q_date" id="q_date" />
					
					<select name="q_type" id="q_type">
						<option value="All">Tour Type</option>
						<option value="abroad">Abroad</option>
						<option value="domestic">Domestic</option>
					</select>
					
					<input type="submit" name="q_search" id="q_search" value="Search"/>
				</form>
				</fieldset>
				<?php 
					/* Query Area Php Part */
					$query = "SELECT t.id, t.name, t.location, t.description, t.start_date, t.end_date, t.type, oc.id AS oc_id, oc.name AS oc_name FROM tour t, organizer_company oc WHERE t.organizer_company_id=oc.id ";
					
					if(post("q_search")) {
						$q_name 	= post("q_name");
						$q_location = post("q_location");
						$q_date 	= post("q_date");
						$q_type 	= post("q_type");
						
						if($q_name != "") $query .= "AND t.name LIKE '%$q_name%' ";
						if($q_location != "") $query .= "AND t.location LIKE '%$q_location%' ";
						if($q_date != "") $query .= "AND t.start_date <= '$q_date' AND t.end_date >= '$q_date' ";
						if($q_type != "" && $q_type != "All") $query .= "AND t.type = '$q_type' ";
					}
				?>
			</div>
			
			<table border="" style="margin-top: 0px;">
				<thead>
					<tr>
						<th>Name</th>
						<th>Location</th>
						<th>Start Date</th>
						<th>End Date</th>
						<th>Type</th>
						<th>Organizer Company</th>
					</tr>
				</thead>
				<tbody>
				<?php
					$result = sql_query($query);
					while ( $tuple = mysql_fetch_assoc ( $result ) ) {
						?>
						<tr>
							<td><a href="tour_detail.php?id=<?php echo $tuple["id"]; ?>"><?php echo $tuple["name"]; ?></a></td>
							<td><?php echo $tuple["location"]; ?></td>
							<td><?php echo $tuple["start_date"]; ?></td>
							<td><?php echo $tuple["end_date"]; ?></td>
							<td><?php echo $tuple["type"]; ?></td>
							<td><a href="company_detail.php?id=<?php echo $tuple["oc_id"]; ?>"><?php echo $tuple["oc_name"]; ?></a></td>
						</tr>
						<?php
					}
				?>
			</tbody>
			</table>

		</div>
		<!-- CONTENT ENDS-->		
		
		<?php include "html/footer.html"; ?>
		
	</div>

</body>
</html>